feat: add SIP-010 fungible token batch transfer contract (Clarity 4)#1
Open
cocoa007 wants to merge 2 commits into
Open
feat: add SIP-010 fungible token batch transfer contract (Clarity 4)#1cocoa007 wants to merge 2 commits into
cocoa007 wants to merge 2 commits into
Conversation
- send-many-ft.clar: template contract for batch FT transfers - Uses restrict-assets? with with-ft for in-contract post conditions - Same 3-list pattern (5000+5000+4995 = 14,995 recipients/tx) - Fault-tolerant: failed transfers increment fail counter, batch continues - deploy-ft.ts: deployment script with token substitution Deploy one per token (like nft-airdrop.clar per campaign). contract-call? requires compile-time contract refs in Clarity, so the template has .token-placeholder replaced at deploy time. Signed-by: cocoa007.btc (BTC: bc1qv8dt3v9kx3l7r9mnz2gj9r9n9k63frn6w6zmrt)
- send-many-ft.clar is now fully generic — works with any SIP-010 token - Key pattern: trait is the fold accumulator, so fold helper can call contract-call? on it directly. Counts tracked via data-vars. - Caller passes token-name (string-ascii) for restrict-assets? post condition - Removed deploy-ft.ts (no template substitution needed) - Single deployment, works for all SIP-010 tokens Signed-by: cocoa007.btc (BTC: bc1qv8dt3v9kx3l7r9mnz2gj9r9n9k63frn6w6zmrt)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
send-many-ft.clar— a generic contract for batch SIP-010 fungible token transfers. Works with any SIP-010 token, no per-token deployment needed.Key Pattern: Trait as Fold Accumulator
The main challenge: Clarity's
foldhelpers have a fixed(element, accumulator)signature and can't access trait parameters from the outer scope.Solution: Pass the
<ft-trait>itself as the fold accumulator. The fold helper receives it as a parameter, callscontract-call? token transferdirectly, and returns the trait for the next iteration. Counts are tracked via data-vars.Clarity 4 Post Conditions
Uses
restrict-assets?withwith-ft— caller passes the token name for the post condition:If actual transfers exceed
total-amount, the entire tx rolls back. No client-side post conditions needed.Interface
Returns
{ok: uint, fail: uint}— successful and failed transfer counts.Features